<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 * ^2_3^
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerInterface;
use Hyperf\Logger\LoggerFactory;


/**
 * index
 * Class IndexController
 * @Controller()
 * @package App\Controller
 * @author cenyebao^2_3^
 * email 1142733640@qq.com
 */
class IndexController extends AbstractController
{

    /**
     * index
     * @return array
     * @author cenyebao^2_3^
     * email 1142733640@qq.com
     */
    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        //// 日志
        // 第一个参数对应日志的name(日志channel名称), 第二个参数对应 config/autoload/logger.php 内的key
        $logger = ApplicationContext::getContainer()->get(LoggerFactory::class)->get('cyb_log', 'default');
        $logger->debug('[DEBUG]_调试信息(^2_3^)');
        $logger->info('[INFO]_信息日志');

        return [
            'method' => $method,
            'message' => "^2_3^ Hello {$user}.",
        ];
    }

    /**
     * hello
     * (Controller()注解路由定义)
     * @RequestMapping(path="hello", methods="get,post")
     * @return array
     * @author cenyebao^2_3^
     * email 1142733640@qq.com
     */
    public function hello()
    {
        $name = $this->request->input('name', '^2_3^');
        $method = $this->request->getMethod();

        return [
            'method' => $method,
            'msg' => "hello, {$name}",
        ];
    }
}
